
#include <mian_util.h>
#include "compress_algo.h"


void bitEncode(unsigned int* word, unsigned int* numWord,
		const char* data, const unsigned long n) {
	*numWord = ceil(n/((double)(sizeof(unsigned int)*8)));
	memset(word, 0, sizeof(unsigned int)*(*numWord));

	byte* output = (byte*)word;
	for(unsigned long i = 0; i < n; i++) {
		if(data[i] == '+') {
			BIT_SET1(output, i);
		}	
	}
}


void bitDecode(char* data, const unsigned long n, 
                const unsigned int* word, const unsigned int numWord) {
	memset(data, 0, sizeof(char)*n);
	byte* input = (byte*)word;

	for(unsigned int i = 0; i < n; i++) {
		if(BIT_GET(input, i) != 0) { // == 1
			data[i] = '+';
		} else {
			data[i] = '-';
		}
	}
}

